
* create a categorical variable representing your treatments
gen treatment=.
replace treatment=1 if Q75 !=.
replace treatment=2 if Q18 !=.
replace treatment=3 if Q76 !=.
replace treatment=4 if Q77 !=.
replace treatment=5 if Q78 !=.
replace treatment=6 if Q79 !=.
tab treatment


* label the treatment variable values
label define treatment 1 "US baseline" 2 "UN baseline" 3 "UN Americans at risk" 4 "UN success likely" 5 "UN high US military fatalities" 6 "UN genocide"
label values treatment treatment
tab treatment


* create and label a binary variable coded as 1 if you support the intervention (in either the US or UN conditions) and a 0 if you do not
gen approve_US_UN_binary=.
replace approve_US_UN_binary=1 if Q39_1==4 | Q39_1==5 | Q39_1==6
replace approve_US_UN_binary=0 if Q39_1==1 | Q39_1==2 | Q39_1==3
replace approve_US_UN_binary=1 if A_approve_UN__1==4 | A_approve_UN__1==5 | A_approve_UN__1==6
replace approve_US_UN_binary=0 if A_approve_UN__1==1 | A_approve_UN__1==2 | A_approve_UN__1==3

label define approve_US_UN_binary 1 "approve intervention" 0 "oppose intervention"
label values approve_US_UN_binary approve_US_UN_binary

tab approve_US_UN_binary

* create a continuous variable that includes both US and UN conditions
gen approve_US_UN_continuous=A_approve_UN__1
replace approve_US_UN_continuous=Q39_1 if treatment==1

* create and label a binary variable coded as 1 if you said the US or UN would be more effective than the other (in either the US or UN conditions) and a 0 you siad less effective
gen efficacy_US_UN_binary=.
replace efficacy_US_UN_binary=1 if Q31_1==4 | Q31_1==5 | Q31_1==6
replace efficacy_US_UN_binary=0 if Q31_1==1 | Q31_1==2 | Q31_1==3
replace efficacy_US_UN_binary=1 if Q43_1==4 | Q43_1==5 | Q43_1==6
replace efficacy_US_UN_binary=0 if Q43_1==1 | Q43_1==2 | Q43_1==3
label define efficacy_US_UN_binary 0 "UN/US less effective" 1 "UN/US more effective"
label values efficacy_US_UN_binary efficacy_US_UN_binary
tab efficacy_US_UN_binary


* plot the means for approve_US_UN_continuous for each condition
set scheme modern
reg approve_US_UN_continuous i.treatment
margins, over (treatment)
mplotoffset, offset(0.16) recast(scatter) plotregion(margin(5 5 0 0)) plotopts(mlabel(_margin) mlabangle(0) yvarformat(%5.2g) mlabsize(1.6) msize(1.8)) ylabel(#10,grid) yscale(range(1 6)titlegap(*12)) ytitle("mean approve intervention") xtitle("condition") xlabel(, angle(45) labsize(vsmall)) title("support for humanitarian intervention" "by experimental condition", size(medium)) legend(off) xsize(11) ysize(10)

* compare the means for approve_US_UN_continuous in each condition
mean approve_US_UN_continuous, over(treatment) coeflegend
* US vs UN baselines (no significant differences)
test _b[c.approve_US_UN_continuous@1.treatment] = _b[c.approve_US_UN_continuous@2.treatment]
* UN baseline vs other UN treatments (no significant differences)
test _b[c.approve_US_UN_continuous@2.treatment] = _b[c.approve_US_UN_continuous@3.treatment]
test _b[c.approve_US_UN_continuous@2.treatment] = _b[c.approve_US_UN_continuous@4.treatment]
test _b[c.approve_US_UN_continuous@2.treatment] = _b[c.approve_US_UN_continuous@5.treatment]
test _b[c.approve_US_UN_continuous@2.treatment] = _b[c.approve_US_UN_continuous@6.treatment]
* UN Americans at risk vs UN high US military fatalities (this is significant)
test _b[c.approve_US_UN_continuous@3.treatment] = _b[c.approve_US_UN_continuous@5.treatment]


* plot the means for approve_US_UN_binary for each condition
set scheme modern
logit approve_US_UN_binary i.treatment
margins, over (treatment)
mplotoffset, offset(0.16) recast(scatter) plotregion(margin(5 5 0 0)) plotopts(mlabel(_margin) mlabangle(0) yvarformat(%5.2g) mlabsize(1.6) msize(1.8)) ylabel(#10,grid) yscale(range(0 1)titlegap(*12)) ytitle("% approve intervention") xtitle("condition") xlabel(, angle(45) labsize(vsmall)) title("support for humanitarian intervention" "by experimental condition", size(medium)) legend(off) xsize(11) ysize(10)

* compare the means for approve_US_UN_binary in each condition
mean approve_US_UN_binary, over(treatment) coeflegend
* US vs UN baselines (no significant differences)
test _b[c.approve_US_UN_binary@1.treatment] = _b[c.approve_US_UN_binary@2.treatment]
* UN baseline vs other UN treatments (no significant differences)
test _b[c.approve_US_UN_binary@2.treatment] = _b[c.approve_US_UN_binary@3.treatment]
test _b[c.approve_US_UN_binary@2.treatment] = _b[c.approve_US_UN_binary@4.treatment]
test _b[c.approve_US_UN_binary@2.treatment] = _b[c.approve_US_UN_binary@5.treatment]
test _b[c.approve_US_UN_binary@2.treatment] = _b[c.approve_US_UN_binary@6.treatment]
* UN Americans at risk vs UN high US military fatalities (this is significant)
test _b[c.approve_US_UN_binary@3.treatment] = _b[c.approve_US_UN_binary@5.treatment]
test _b[c.approve_US_UN_binary@3.treatment] = _b[c.approve_US_UN_binary@6.treatment]


* create a variable coded as 1 for democrats and 0 for republicans
gen rep_vs_dem = Q66
recode rep_vs_dem 1=1 2=0 else=.
label define rep_vs_dem 0 "Democrat" 1 "Republican", replace
label values rep_vs_dem rep_vs_dem
tab rep_vs_dem

*plot the means for approve_US_UN_binary for each condition by party ID
logit approve_US_UN_binary treatment##rep_vs_dem
margins treatment#rep_vs_dem
mplotoffset, offset(0.2) recast(scatter) plotregion(margin(5 5 0 0)) plotopts(mlabel(_margin) mlabangle(0) yvarformat(%5.2g) mlabsize(1.6) msize(1.8)) ylabel(#10,grid) yscale(range(0 1)titlegap(*12)) ytitle("% approve intervention") xtitle("condition") xlabel(, angle(45) labsize(vsmall)) title("support for humanitarian intervention" "by experimental condition and party ID", size(medium)) legend() xsize(11) ysize(10)

* test for interaction between party ID and conditions (i.e., do the treatments move republicans more or less than democrats) using UN baseline as (rb2.) as the comparison condition
contrast rb2.treatment#rep_vs_dem, effects


*plot the means for approve_US_UN_binary for each condition by political ideology 
logit approve_US_UN_binary treatment##political_ideology 
margins treatment#political_ideology 
mplotoffset, offset(0.3) recast(scatter) plotregion(margin(5 5 0 0)) plotopts(mlabel(_margin) mlabangle(0) yvarformat(%5.2g) mlabsize(1.6) msize(1.8)) ylabel(#10,grid) yscale(range(0 1)titlegap(*12)) ytitle("% approve intervention") xtitle("condition") xlabel(, angle(45) labsize(vsmall)) title("support for humanitarian intervention" "by experimental condition and political ideology", size(medium)) legend() xsize(11) ysize(10)



*US vs UN treatment variable 

gen US_UN_treatment=.
replace US_vs_UN_treatment = 1 if treatment==1 *US baseline 
replace US_vs_UN_treatment = 0 if treatment==2 * UN baselie 
logit approve_US_UN_binary rep_vs_dem##US_vs_UN_treatment

*US gov perception of UN (Q36) 

gen UN_gov_perception=. 
replace UN_gov_perception=1 if Q36_1==4 | Q36_1==5 | Q36_1==6 
replace UN_gov_perception=0 if Q36_1==1 | Q36_1==2 | Q36_1==3
replace UN_gov_perception=1 if Q50_1==4 | Q50_1==5 | Q50_1==6
replace UN_gov_perception=0 if Q50_1==1 | Q50_1==2 | Q50_1==3
label define UN_gov_perception 0 "US gov opposes UN" 1 "US gov supports UN"
label values UN_gov_perception UN_gov_perception
tab UN_gov_perception

*compare US gov perception of UN with party ID
logit UN_gov_perception rep_vs_dem if Duration__in_seconds_ > 360 

*measuring cmsopolitan relation with gov perception 
logit UN_gov_perception age_respondent Q63 rep_vs_dem if Duration__in_seconds_ > 360

* create a variable coded numerically for education level (Q63) 
gen education_level = Q63
recode education_level 1=0 2=0 3=1 4=1 5=1 6=1 
label define education_level 0 "No Education" 1 "Educated", replace
label values education_level education_level
tab education_level

*create variable coded numerically for UN approval (Q53)
gen impt_UN_approval=. 
replace impt_UN_approval=1 if Q53_1==4 | Q53_1==5 | Q53_1==6 
replace impt_UN_approval=0 if Q53_1==1 | Q53_1==2 | Q53_1==3
label impt_UN_approval 0 "not important" 1 "important"
label values impt_UN_approval impt_UN_approval
tab impt_UN_approval

*create variable coded numerically for UN advancing interests of US (Q54)
gen UN_interestsUS=. 
replace UN_interestsUS=1 if Q53_1==4 | Q53_1==5 | Q53_1==6 
replace UN_interestsUS=0 if Q53_1==1 | Q53_1==2 | Q53_1==3
label UN_interestsUS 0 "disagree" 1 "agree"
label values UN_interestsUS UN_interestsUS
tab UN_interestsUS 

*create cosmopolitan political ideology 

gen political_ideology = Q67
recode political_ideology 1=0 2=0 3=1 4=1 5=1 
label define political_ideology 0 "conservative" 1 "liberal", replace
label values political_ideology political_ideology
tab political_ideology

*create variable for younger than 35 and older than 35 
gen young_vs_else = Q62
recode young_vs_else 1=0 2=1 3=1 
label define young_vs_else 0 "Younger than 35" 1 "Older than 35", replace
label values young_vs_else young_vs_else 
tab young_vs_else

*create variable for education  
gen collegegrad = Q63
recode collegegrad 5=0 6=0 1=1 2=1 3=1 4=1 
label define collegegrad 0 "College Graduate" 1 "Not a College Graduate", replace
label values collegegrad collegegrad
tab collegegrad


*create variable for respondent sex 
gen respondentsex= Q61
recode respondentsex 1=0 2=1 3=0
label define respondentsex 0 "Not Female" 1 "Female", replace
label values respondentsex respondentsex
tab respondentsex

*create variable democrats v everyone else 
gen dem_vs_else = 0
replace dem_vs_else = 1 if rep_vs_dem==0
tab dem_vs_else rep_vs_dem

*demograhpic regression model 

logit approve_US_UN_binary collegegrad dem_vs_else young_vs_else respondentsex if Duration__in_seconds_ > 360


*create variable for independents 
gen independents_vs_else = 0
replace independents_vs_else = 1 if Q66==3
tab independents_vs_else


*create variable coded numerically for UN interaction w US sovereign powers (Q37 and Q51)
gen UN_sovereign_US=. 
replace UN_sovereign_US=1 if Q37_1==4 | Q37_1==5 | Q37_1==6 
replace UN_sovereign_US=0 if Q37_1==1 | Q37_1==2 | Q37_1==3
replace UN_sovereign_US=1 if Q51_1==4 | Q51_1==5 | Q51_1==6
replace UN_sovereign_US=0 if Q51_1==1 | Q51_1==2 | Q51_1==3
label define UN_sovereign_US 0 "Disagree" 1 "Agree"
label values UN_sovereign_US UN_sovereign_US
tab UN_sovereign_US 

*generate employed variable 
gen employed = Q68
recode employed 1=0 2=0 else=. 
label define employed 0 "employed", replace 
label values employed employed 
tab employed 


* get mean and standard error 
tabstat female, stats(mean sd semean min max n)
